#pragma once

#include "PackageImport.h"

#include "Namespace.h"
#include "Package.h"

namespace uml {

void PackageImport::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    DirectedRelationship::fromJson(json, errorList);
    importedPackage_ = JsonSerializable::create<Package>(json.value("importedPackage"), errorList);

    importingNamespace_ = JsonSerializable::create<Namespace>(json.value("importingNamespace"), errorList);

    visibility_ = (VisibilityKind)json.value("visibility").toInt((int)visibility_);
}

void PackageImport::toJson(QJsonObject& json) {
    DirectedRelationship::toJson(json);
    if (importedPackage_) {
        QJsonObject importedPackage_json;
        importedPackage_->toJson(importedPackage_json);
        json.insert("importedPackage", importedPackage_json);
    }
    if (importingNamespace_) {
        QJsonObject importingNamespace_json;
        importingNamespace_->toJson(importingNamespace_json);
        json.insert("importingNamespace", importingNamespace_json);
    }
    json.insert("visibility", (int)visibility_);
}

/// <summary>
/// importedPackage getter
/// Specifies the Package whose members are imported into a Namespace.
/// </summary>
shared_ptr<Package> PackageImport::importedPackage() const {
    return importedPackage_;
}

/// <summary>
/// importedPackage setter
/// Specifies the Package whose members are imported into a Namespace.
/// </summary>
void PackageImport::setImportedPackage(shared_ptr<Package> value) {
    importedPackage_ = value;
}

/// <summary>
/// importingNamespace getter
/// Specifies the Namespace that imports the members from a Package.
/// </summary>
shared_ptr<Namespace> PackageImport::importingNamespace() const {
    return importingNamespace_;
}

/// <summary>
/// importingNamespace setter
/// Specifies the Namespace that imports the members from a Package.
/// </summary>
void PackageImport::setImportingNamespace(shared_ptr<Namespace> value) {
    importingNamespace_ = value;
}

/// <summary>
/// visibility getter
/// Specifies the visibility of the imported PackageableElements within the
/// importingNamespace, i.e., whether imported Elements will in turn be visible to
/// other Namespaces. If the PackageImport is public, the imported Elements will be
/// visible outside the importingNamespace, while, if the PackageImport is private,
/// they will not.
/// </summary>
VisibilityKind PackageImport::visibility() const {
    return visibility_;
}

/// <summary>
/// visibility setter
/// Specifies the visibility of the imported PackageableElements within the
/// importingNamespace, i.e., whether imported Elements will in turn be visible to
/// other Namespaces. If the PackageImport is public, the imported Elements will be
/// visible outside the importingNamespace, while, if the PackageImport is private,
/// they will not.
/// </summary>
void PackageImport::setVisibility(VisibilityKind value) {
    visibility_ = value;
}

} // namespace uml
